﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataCollector.Entity;
using EnergyControl_SeverDlg;


namespace SilverlightApp.Web.DataBase
{
    public class MonitorDataDao
    {
        public void Insert(string zoneId,MonitorResult mr)
        {
            using (DataClassesForInsertDataContext dc = new DataClassesForInsertDataContext())
            {
                if (dc.MonitorTable2.Count() > 0)
                {
                    MonitorTable2 Tabledel = dc.MonitorTable2.First();
                    dc.MonitorTable2.DeleteOnSubmit(Tabledel);
                    dc.SubmitChanges();
                }

                MonitorTable2 t2 = new MonitorTable2();
                t2.zone_id = zoneId;
                t2.export_time = DateTime.Now.ToString("yyyyMMddHHmmss");
                t2.humidity = decimal.Parse(mr.Humidity.ToString());
                t2.temperature = decimal.Parse(mr.Temperature.ToString());
                t2.illumination = decimal.Parse(mr.Illumination.ToString());
                dc.MonitorTable2.InsertOnSubmit(t2);
                dc.SubmitChanges();
            }
        }
    }
}